package cn.hzking.gjmall.adpters.address;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.my.AddAdressActivity;
import cn.hzking.gjmall.bean.address.AddressSimpleBean;
import cn.hzking.gjmall.utils.OnClickEvent;

/**
 * Created by Administrator on 2018/3/2.
 */

public class AddressAdapter extends BaseQuickAdapter<AddressSimpleBean.DataBean.DeliveryAddressesListBean,BaseViewHolder> {
    private AddressDefault addressDefault;

    public AddressDefault getAddressDefault() {
        return addressDefault;
    }

    public void setAddressDefault(AddressDefault addressDefault) {
        this.addressDefault = addressDefault;
    }

    public AddressAdapter(int layoutResId, @Nullable List<AddressSimpleBean.DataBean.DeliveryAddressesListBean> data) {
        super(layoutResId, data);
    }



    @Override
    protected void convert(BaseViewHolder helper, final AddressSimpleBean.DataBean.DeliveryAddressesListBean item) {
        TextView nameTv=helper.getView(R.id.tv_name);
        TextView telTv=helper.getView(R.id.tv_tel);
        TextView addressTv=helper.getView(R.id.tv_address);
        RelativeLayout editRl=helper.getView(R.id.rl_edit);
        RelativeLayout delRl=helper.getView(R.id.rl_del);
        RelativeLayout defaultRl=helper.getView(R.id.rl_default);
        ImageView defaultIv=helper.getView(R.id.iv_default);
        if(item.isIsdefault()){
            defaultIv.setImageResource(R.mipmap.gouwuche_xuanzhong);
        }else {
            defaultIv.setImageResource(R.mipmap.gouwuche_xuanze);
        }
       defaultRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                addressDefault.setdefault(item.getId());
            }
        });
        delRl.setOnClickListener(new OnClickEvent() {
            @Override
            public void singleClick(View v) {
                addressDefault.del(item.getId());
            }
        });
       nameTv.setText(item.getReceiverName());
       telTv.setText(item.getReceiverTel());
       addressTv.setText(item.getLongAddress());
       editRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, AddAdressActivity.class);
                intent.putExtra("name",item.getReceiverName());
                intent.putExtra("tel",item.getReceiverTel());
                intent.putExtra("provinceName",item.getProvinceName());
                intent.putExtra("cityName",item.getCityName());
                intent.putExtra("districtName",item.getDistrictName());
                intent.putExtra("street","");
                intent.putExtra("districtId",""+item.getDistrictId());
                intent.putExtra("provinceId",""+item.getProvinceId());
                intent.putExtra("cityId",""+item.getCityId());
                mContext.startActivity(intent);
            }
        });

    }
    public interface AddressDefault{
        public void setdefault(int addressId);
        public void del(int addressId);
    }
}
